package com.qf.controller;

import com.qf.pojo.User;
import com.qf.pojo.UserVo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author Wy
 * @version V1.0
 * @Project MavenDemo
 * @Package com.qf.controller
 * @Description:
 * @Date 2022/6/7 21:30
 */
@Controller
@RequestMapping("/param")
public class ParamController {
    @RequestMapping("/test1")
    public String test1(HttpServletRequest request, HttpServletResponse response, Model model){
        String id = request.getParameter("id");
        String name = request.getParameter("name");
        System.out.println("==="+id);
        System.out.println("===="+name);
        model.addAttribute("id", id);
        model.addAttribute("name",name);



        return  "hello";
    }
    @RequestMapping("/test2")
    public String test1(Integer id, String name, Model model){

        System.out.println("==="+id);
        System.out.println("===="+name);
        model.addAttribute("id", id);
        model.addAttribute("name",name);



        return  "hello";
    }
    @RequestMapping("/test3")
    public String test3(User user, Model model) {
        System.out.println("========user=======" + user);

        //相当于request.setAttribute方法, 将数据放入请求域中带到页面中展示使用
        model.addAttribute("user", user);

        //指定返回数据并跳转到hello页面
        return "hello";
    }

    @RequestMapping("/test4")
    public String test4(String [] hobby, Model model) {
        System.out.println("========user=======" + hobby);

        //相当于request.setAttribute方法, 将数据放入请求域中带到页面中展示使用
        model.addAttribute("hobby", hobby);

        //指定返回数据并跳转到hello页面
        return "hello";
    }
    @RequestMapping("/test5")
    public String test5(UserVo userVo, Model model) {
        System.out.println("========user=======" + userVo);

        //相当于request.setAttribute方法, 将数据放入请求域中带到页面中展示使用


        //指定返回数据并跳转到hello页面
        return "hello";
    }

    @RequestMapping("/test6/{xx}/{name}")
    public String test6(@PathVariable("xx")Integer id,@PathVariable("name") String name) {
        System.out.println("========user=======" +id+name);

        //相当于request.setAttribute方法, 将数据放入请求域中带到页面中展示使用


        //指定返回数据并跳转到hello页面
        return "hello";
    }

    @RequestMapping("/test7")
    public String test7(Integer id,String name, Model model) {
        System.out.println("========user=======" + id+name);

        //相当于request.setAttribute方法, 将数据放入请求域中带到页面中展示使用
            model.addAttribute("id" ,id);
            model.addAttribute("name", name);

        //指定返回数据并跳转到hello页面
        return "forward:/param/test3";
    }
    @RequestMapping("/err")
    public String test8(){
        System.out.println("========测试异常处理器是否好用==========");

        int i = 1/0;
        return "hello";
    }
}
